Skip to content

Conversation

IliaShuliatikov
Copy link
Contributor

Fix incorrect runtime member info (RuntimePropertyInfo, RuntimeMethodInfo, RuntimeEventInfo, RuntimeFieldInfo, RuntimeConstructorInfo) hashcode calculation. Previously it did not include the reflected type, resulting in different sub classes having the same hashcode for properties declared in the base class.

Fixes #114280

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 6, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Oct 6, 2025

Can we add some tests to validate that the hashcodes are different for different reflected types? (The test should try multiple types to be resilient against hash collisions.)

@jkotas
Copy link
Member

jkotas commented Oct 7, 2025

Test System.Reflection.Tests.MethodInfoTests.GetHashCode_WithSameBaseClass_ShouldNotEqual has failed.

Looks like NativeAOT needs the same fix. NativeAOT has a separate implementation of reflection that lives under src\coreclr\nativeaot.

Copy link

@jairbubbles jairbubbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comment regarding consistency between Equals and GetHashCode on the different classes.
In some cases it might be an issue on the Equals itself and is probably out of the scope of this PR.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jkotas jkotas merged commit 0edefd0 into dotnet:main Oct 11, 2025
124 of 128 checks passed
@IliaShuliatikov IliaShuliatikov deleted the fix-incorrect-RuntimeMemberInfo-hashcode branch October 11, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RuntimePropertyInfo performance regression when used in a hash table

4 participants